package com.dmap.admin.controller.backgroundv2;

import com.dmap.admin.constants.AdminConstant;
import com.dmap.admin.service.backgroundv2.CompanyStructureService;
import com.dmap.admin.vo.backgroundv2.CompanyStructureVo;
import com.dmap.base.constants.Constant;
import com.dmap.base.vo.BaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * \* User: helei
 * \* Date: 27/05/18
 * \* Description:
 * \
 */
@Api(value = "个人数据服务系统-组织结构管理", description = "background/组织结构管理")
@Controller
@RequestMapping(value = "/background/pmpd-admin-server/v2/companyStructure/")
public class CompanyStructureController {

    @Resource
    private CompanyStructureService companyStructureService;

    @ResponseBody
    @ApiOperation(value = "根据companyId查询组织结构", notes = "1. 必填： companyId, companyType; ")
    @RequestMapping(value = "select/selectByCompanyId", method = RequestMethod.GET)
    public BaseVo selectByCompanyId(@RequestParam String companyId,
                                    @RequestParam Integer companyType) {
        BaseVo baseVo = new BaseVo();
        if (StringUtils.isBlank(companyId) || !StringUtils.isNumeric(companyId)
                || Long.valueOf(companyId).equals(0L)
                || (companyType != AdminConstant.COMPANY_TYPE_HEAD && companyType != AdminConstant.COMPANY_TYPE_BRANCH)) {
            baseVo.setCode(Constant.RESPONSE_PARAM_ERROR_CODE);
            baseVo.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return baseVo;
        }
        CompanyStructureVo companyStructureVo = companyStructureService.selectByCompanyId(Long.valueOf(companyId), companyType);
        baseVo.setData(companyStructureVo);
        return baseVo;
    }

}